package com.android.binderserverclient0.mvi2.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.android.binderserverclient0.mvi2.network.ApiService
import com.android.binderserverclient0.mvi2.repository.MainRepository

class ViewModelFactory(private val apiService: ApiService) : ViewModelProvider.Factory {

    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(MainViewModel::class.java)) {
            //通过ViewModelProvider.Factory传递参数,比如ContentResolver、OkHttp服务.
            return MainViewModel(MainRepository(apiService)) as T
        }
        throw IllegalArgumentException("Unknown class")
    }

}